﻿@using System.ComponentModel

<Table DataSource="_data" TreeChildren="item=>item.Children" DefaultExpandAllRows Size="TableSize.Small">
    <Selection />
    <PropertyColumn Property="c=>c.Name" />
    <PropertyColumn Property="c=>c.Age" Width="12%" Sortable />
    <PropertyColumn Property="c=>c.Address" Width="30%" />
</Table>

@code {
    Data[] _data = Array.Empty<Data>();

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        Data person1 = new()
        {
            Key = "1",
            Name = "Person1",
            Age = 42,
            Address = "London No. 1 Lake Park",
        };
        Data person2 = new()
        {
            Key = "2",
            Name = "Person2",
            Age = 22,
            Address = "New York No. 1 Lake Park",
        };
        Data person3 = new()
        {
            Key = "3",
            Name = "Person3",
            Age = 32,
            Address = "Sydney No. 1 Lake Park",
        };
        person1.Children = new[] { person2 };
        person2.Children = new[] { person3 };
        person3.Children = new[] { person1 };
        _data = new[] { person1, person2, person3 };
    }

    public class Data
    {
        [DisplayName("Key")]
        public string Key { get; set; }

        [DisplayName("Name")]
        public string Name { get; set; }

        [DisplayName("Age")]
        public int Age { get; set; }

        [DisplayName("Address")]
        public string Address { get; set; }

        public Data[] Children { get; set; }
    }
}
